<div class="clue" style="color: red; padding: 0px 0px 10px 0px;">
    【操作提示】修改完成后，请点击“保存列表”按钮。<br/>
</div>

<!--列表-->
<table class="am-table am-table-bordered am-table-radius am-table-striped">
    <thead>
        <tr>
            <th width="120px">序号</th>
            <th width="120px">标题</th>
            <th>内容</th>
            <th width="80px">操作</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<style type="text/css">
    .am-table td {
        padding: 5px 15px 5px 15px;
    }
</style>

<div class="button_line">
    <button class="am-btn am-btn-primary btn-add admin_button">新增</button>
    <button class="am-btn am-btn-primary btn-save admin_button">保存列表</button>
</div>

<script>
    // 刷新配置信息
    var boardList = [];
    Classify.queryExt("settings", "board", true, [], function(v) {
        boardList = v;
        fillBoards();
    });

    function fillBoards() {
        var table = $(".am-table tbody");
        table.empty();
        for (var i in boardList) {
            var tr = $("<tr></tr>");
            tr.append('<td><input type="number" class="empty_input order" placeholder="输入序号"/></td>');
            tr.append('<td><input type="text" class="empty_input subject" placeholder="输入标题"/></td>');
            tr.append('<td><textarea rows="3" class="empty_input bcontent" placeholder="输入公告内容" style="width:100%;"/></td>');
            tr.append('<td><a href="#" value="' + i + '">删除</a></td>');
            table.append(tr);
        }

        var orders = $(".am-table input.order");
        var subjects = $(".am-table input.subject");
        var contents = $(".am-table textarea");
        for (var i in boardList) {
            $(orders[i]).val(boardList[i].order);
            $(subjects[i]).val(boardList[i].subject);
            $(contents[i]).val(boardList[i].content);
        }

        $(".am-table a").click(function(e) {
            var i = $(e.currentTarget).attr("value");
            boardList.splice(i, 1);
            fillBoards();
        });
    }

    $(".btn-add").click(function() {
        boardList.push({
            order: 1,
            subject: "",
            content: "",
            time: new Date().Format("yyyy-MM-dd"),
        });
        fillBoards();
    });

    $(".btn-save").click(function() {
        // 回写数据
        var orders = $(".am-table input.order");
        var subjects = $(".am-table input.subject");
        var contents = $(".am-table textarea");
        for (var i in boardList) {
            boardList[i].order = parseInt($(orders[i]).val());
            boardList[i].subject = $(subjects[i]).val();
            boardList[i].content = $(contents[i]).val();
        }

        startLoading();
        Classify.saveExt("settings", "board", boardList, function() {
            stopLoading();
            alert2("保存成功！");
        });
    });
</script>
